package noobteam.deartrainer.service;

import noobteam.deartrainer.mapper.ChatMapper;
import noobteam.deartrainer.mapper.CourseInfoMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author 徐紫印
 */
@Service
public class ChatService {
    @Resource
    private ChatMapper chatMapper;

    /**
     * 创建消息
     */
    public boolean createChat(Map<String, String> chat) {
        boolean isSucceed = false;
        try {
            isSucceed = chatMapper.createChat(chat);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return isSucceed;
    }

    /**
     * 撤回消息
     */
    public boolean deleteChat(Integer chatId) {
        boolean isSucceed = false;
        try {
            isSucceed = chatMapper.deleteChat(chatId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return isSucceed;
    }

    /**
     * 获取用户与某人的消息记录
     */
    public List<Map<String, String>> getChatHistory(Map<String, String> map) {
        List<Map<String, String>> chatHistory = null;
        try {
            chatHistory = chatMapper.getChatHistory(map);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return chatHistory;
    }

    /**
     * 获取用户的所有消息
     */
    public List<Map<String, Object>> getChatAllHistoryOfUser(Map<String, Object> user) {
        List<Map<String, Object>> chatHistory = null;
        try {
            chatHistory = chatMapper.getChatOfUser(user);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return chatHistory;
    }
}
